/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.awt.Image;
import java.net.URL;
import javax.swing.ImageIcon;

/**
 *
 * @author dennis
 */
public class Tile {
    
    private int xPos;
    private int yPos;
    private int tileWidth;
    private int tileHeight;
    private int xOffset;
    private int yOffset;
    
    protected String graphicPath;
    protected Movable movable;

    public Tile(){
        
    }
    
    public Tile(int xPos, int yPos, int tileWidth, int tileHeight){

        this.setTilePosition(xPos, yPos);
        this.setTileSize(tileWidth, tileHeight);
    
    }

    public Tile(int xPos, int yPos, int tileWidth, int tileHeight, Movable movable){
        
        this.setTilePosition(xPos, yPos);
        this.setTileSize(tileWidth, tileHeight);
    
        this.setMovable(movable);
        
    }

    public Tile(Tile tile){
        
        this.xPos = tile.xPos;
        this.yPos = tile.yPos;
        this.tileWidth = tile.tileWidth;
        this.tileHeight = tile.tileHeight;
        this.xOffset = tile.xOffset;
        this.yOffset = tile.yOffset;

        this.graphicPath = tile.graphicPath;
        
        if(tile.hasMovable()){
            if(tile.movable instanceof AvatarMovable){
                this.movable = new AvatarMovable( (AvatarMovable) tile.movable);
            } else if(tile.movable instanceof BoxMovable){
                this.movable = new BoxMovable( (BoxMovable) tile.movable);
            }
        }
    }
    
    public void setTilePosition(int xPos, int yPos){
        this.xPos = xPos;
        this.yPos = yPos;
    }
 
    public int getPosX(){
        return this.xPos;
    }
    
    public int getPosY(){
        return this.yPos;
    }
    
    public void setTileSize(int tileWidth, int tileHeight){
        this.tileWidth = tileWidth;
        this.tileHeight = tileHeight;
    }
    
    public int getOffsetX(){
        return calculateXOffset();
    }
    
    public int getOffsetY(){
        return calculateYOffset();
    }
    
    public int calculateXOffset(){
        this.xOffset = this.xPos * this.tileWidth;
        return this.xOffset;
    }
    
    public int calculateYOffset(){
        this.yOffset = this.yPos * this.tileHeight;
        return this.yOffset;
    }
   
    public boolean hasMovable(){
        if(this.movable instanceof Movable){
            return true;
        }
        return false;
    }
    
    public void setGraphicPath(String graphicPath){
        this.graphicPath = graphicPath;
    }
    
    public String getGraphicPath(){
        return this.graphicPath;
    }
    
        
    public void removeMovable(){
        
        this.setMovable(null);
        this.getGraphicPath();
        
        
    }
    
    public void setMovable(Movable movable){
        this.movable = movable;
    }
 
    public Movable getMovable(){
        return this.movable;
    }
 
    public boolean isAccessible(){
        return false;
    }
    
}
